﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for GioHangCtr
/// </summary>
public class GioHangCtr
{
    
    //public bool Add(ShoppingCart cart,EGioHang gioHang)
    //{
    //    try
    //    {
    //        gioHang.TrangThai = 0;
    //        DataProvider.ExecuteNonQuery("INSERT INTO HoaDon(NgayLap,KhachHang,NguoiNhan,TongTien,HinhThucThanhToan,NgayGiaoHang,DiaChiGiaoHang,SoDT,TrangThai) "+
    //        "VAlUES(@NgayLap,@KhachHang,@NguoiNhan,@TongTien,@HinhThucThanhToan,@NgayGiaoHang,@DiaChiGiaoHang,@SoDT,@TrangThai)",
    //        "@NgayLap",gioHang.NgayLap,"@KhachHang",gioHang.KhachHang,"@NguoiNhan",gioHang.NguoiNhan,"@TongTien",gioHang.TongTien,"@HinhThucThanhToan",gioHang.HinhThucTT,
    //        "@NgayGiaoHang",gioHang.NgayGiao,"@DiaChiGiaoHang",gioHang.DiaChi,"@SoDT",gioHang.SoDT,"@TrangThai",gioHang.TrangThai
    //        );
    //        string MaHoaDon = DataProvider.ExecuteScalar("SELECT ISNULL(MAX(MaHD), 0) FROM HoaDon", null).ToString();
    //        for(int i=0;i<cart.Rows.Count;i++)
    //        {
    //            DataRow r = cart.Rows[i];
    //            DataProvider.ExecuteNonQuery("INSERT INTO ChiTietHoadon VALUES(@MaHD,@MaSP,@SoLuong,@Gia,@GiamGia,@ThanhTien)",
    //                "@MaHD", MaHoaDon, "@MaSP", r["MaSP"].ToString(), "@SoLuong",r["SoLuong"].ToString(), "@Gia",r["Gia"].ToString(), "@GiamGia",r["GiamGia"].ToString(), "@ThanhTien",r["ThanhTien"].ToString());
    //            int soluong = Int32.Parse( DataProvider.ExecuteScalar("SELECT soluong FROM SanPham WHERE MaSP =@MaSP","@MaSP", r["MaSP"].ToString()).ToString());
    //            string sql = "UPDATE sanpham set soluong=" + (soluong - Int32.Parse(r["SoLuong"].ToString())) + " where masp=@MaSP ";
    //            DataProvider.ExecuteNonQuery(sql, "@MaSP", r["MaSP"].ToString());
    //        }
    //        return true;
    //    }
    //    catch (Exception ex)
    //    {
    //        throw ex;
    //    }
    //}
}